package com.me.jingdongshop.ui.fragment;

import android.os.Message;
import android.view.View;
import android.widget.TextView;

import com.me.common.base.BaseFragment;
import com.me.jingdongshop.R;
import com.me.jingdongshop.dagger2.component.DaggerTestFragmentComponent;
import com.me.jingdongshop.dagger2.module.TestFragmentModule;
import com.me.jingdongshop.model.bean.Home;
import com.me.jingdongshop.model.bean.HomeQuick;
import com.me.jingdongshop.model.bean.HomeRecommendedBrand;
import com.me.jingdongshop.model.bean.HotproductBean;
import com.me.jingdongshop.model.bean.LimitbuyBean;
import com.me.jingdongshop.model.bean.NewproductBean;
import com.me.jingdongshop.model.protocol.IHttpService;
import com.me.jingdongshop.presenter.TestFragmentPre;

import java.util.List;

import javax.inject.Inject;

/**
 * Created on 2017/5/5.
 * 测试网络请求
 * @author Chilam
 */

public class TestFragment extends BaseFragment {
    TextView mTextView;
    private HomeRecommendedBrand mBrandBean;

    @Override
    public int getLayoutRes() {
        return R.layout.test_view;
    }

    @Override
    public void initView() {
        mTextView = findView(R.id.tv_test);
    }

    @Override
    public void initListener() {

    }
    @Inject
    TestFragmentPre mTestFragmentPre;
    @Override
    public void initData() {
        DaggerTestFragmentComponent.builder()
                .testFragmentModule(new TestFragmentModule(this))
                .build().inject(this);

//        mTestFragmentPre.getHomeData();
//        mTestFragmentPre.getBrandData();
//        mTestFragmentPre.getTopicData();
//        mTestFragmentPre.getLimitbuyData();
//        mTestFragmentPre.getNewproduct();
        mTestFragmentPre.getHotproduct();
    }

    @Override
    public void onClick(View v, int id) {

    }
    private Home home;
    @Override
    public void onHttpSuccess(int reqType, Message msg) {
        if (reqType == IHttpService.HTTP_HOTPRODUCT){
            HotproductBean bean = (HotproductBean) msg.obj;
            List<HotproductBean.ProductListBean> productList = bean.getProductList();
            String name = productList.get(0).getName();
            System.out.println();
        }
        if (reqType == IHttpService.HTTP_NEWPRODUCT){
            NewproductBean bean = (NewproductBean) msg.obj;
            List<NewproductBean.ProductListBean> productList = bean.getProductList();
            String name = productList.get(0).getName();
            System.out.println();
        }
        if (reqType == IHttpService.HTTP_LIMITBUY){
           LimitbuyBean bean = (LimitbuyBean) msg.obj;
            List<LimitbuyBean.ProductListBean> productList = bean.getProductList();
            String name = productList.get(0).getName();
            System.out.println();
        }
        if (reqType == IHttpService.HTTP_HOME){
            home = (Home) msg.obj;
            List<Home.HomeTopicBean> homeTopic = home.getHomeTopic();
            String title = homeTopic.get(0).getTitle();
            System.out.println();
        }

        if (reqType == IHttpService.HTTP_BRAND){
            mBrandBean = (HomeRecommendedBrand) msg.obj;
            List<HomeRecommendedBrand.BrandBean> brand = mBrandBean.getBrand();
            int id = brand.get(0).getId();
            String key = brand.get(0).getKey();
            System.out.println(android.R.attr.id +"");
       }
        if (reqType == IHttpService.HTTP_TOPIC){
            HomeQuick bean = (HomeQuick) msg.obj;
            List<HomeQuick.TopicBean> topic = bean.getTopic();
            String name = topic.get(0).getName();
            System.out.println();
        }
    }

    @Override
    public void onHttpError(int reqType, String error) {

    }
}
